// 权限校验函数
import ACCESS_ENUM from "@/access/accessEnum";

const CheckAccess = (loginUser: any, needAccess = ACCESS_ENUM.NOT_LOGIN) => {
  const loginUserAccess = loginUser?.userRole ?? ACCESS_ENUM.NOT_LOGIN;
  if (needAccess === ACCESS_ENUM.NOT_LOGIN) {
    return true;
  }
  // 需要的权限为用户
  if (needAccess === ACCESS_ENUM.USER) {
    // 如果未登录
    if (loginUserAccess === ACCESS_ENUM.NOT_LOGIN) {
      return false;
    }
  }
  // 需要权限为admin
  if (needAccess === ACCESS_ENUM.ADMIN) {
    // 如果登录为用户
    if (loginUserAccess !== ACCESS_ENUM.ADMIN) {
      return false;
    }
  }
  return true;
};

export default CheckAccess;
